<?php

namespace app\admin\controller;

use app\model\Welfare;
use app\model\WorkTag;

/**
 *  标签管理
 */
class Tag extends Auth
{
    /**
     * 福利标签列表
     *
     * @return void
     */
    public function welfareList()
    {
        $list = Welfare::field('id, welfare_name')->select();
        success('福利标签列表', $list);
    }

    /**
     * 添加福利标签
     *
     * @return void
     */
    public function createWelfare()
    {
        $welfare_name = input('welfare_name');
        if (empty($welfare_name)) {
            error('缺少标签名');
        }
        try {
            Welfare::create(['welfare_name' => $welfare_name]);
            success('添加成功');
        } catch (\Exception $e) {
            error($e->getMessage());
        }
    }

    /**
     * 删除福利标签
     *
     * @return void
     */
    public function delWelfare()
    {
        $id = input('id');
        if (empty($id)) {
            error('缺少id');
        }
        try {
            Welfare::where('id', $id)->delete();
            success('删除成功');
        } catch (\Exception $e) {
            error($e->getMessage());
        }
    }

    /**
     * 职位标签列表
     *
     * @return void
     */
    public function workTagList()
    {
        $list = WorkTag::field('id, tag')->select();
        success('职位标签列表', $list);
    }

    /**
     * 添加职位标签
     *
     * @return void
     */
    public function createWorkTag()
    {
        $tag = input('tag');
        if (empty($tag)) {
            error('缺少标签名');
        }
        try {
            WorkTag::create(['tag' => $tag]);
            success('添加成功');
        } catch (\Exception $e) {
            error($e->getMessage());
        }
    }

    /**
     * 删除职位标签
     *
     * @return void
     */
    public function delWorkTag()
    {
        $id = input('id');
        if (empty($id)) {
            error('缺少id');
        }
        try {
            WorkTag::where('id', $id)->delete();
            success('删除成功');
        } catch (\Exception $e) {
            error($e->getMessage());
        }
    }
}